﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// point 的摘要说明
/// </summary>
public class point
{
	public point()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//

	}

    const string constr = "server=60.191.254.162,3433;User ID='ten9158room_web_v2';Password='P@t*5!9Tg';Pooling=true;Max Pool Size=35;database=TenTiange;Connection Reset=FALSE";
    //const string constr = "server=10.191.231.133,3433;User ID='ten9158room_web_v2';Password='P@t*5!9Tg';Pooling=true;Max Pool Size=35;database=TenTiange;Connection Reset=FALSE";
    //const string constr = "server=122.227.23.112,3433;User ID='tenroom';Password='tenroom';Pooling=true;Max Pool Size=35;database=TenRoomTest;Connection Reset=FALSE";
    /// <summary>
    /// 修改用户奖励
    /// </summary>
    /// <param name="idx"></param>
    /// <param name="level"></param>
    public void updatePoint(int idx, int exps, int gold)
    {

        SqlParameter[] pars ={
                    SqlHelper.MakeInParam("@idx", SqlDbType.Int, 4, idx), 
                    SqlHelper.MakeInParam("@exps", SqlDbType.Int, 4, exps), 
                    SqlHelper.MakeInParam("@gold", SqlDbType.Int, 4, gold) };
        SqlHelper.ExecuteNonQuery(constr, CommandType.StoredProcedure, "updatePoint", pars);

        //if (gold > 0)
        //{

        //    SqlParameter[] pars ={ SqlHelper.MakeInParam("@idx", SqlDbType.Int, 4, idx), SqlHelper.MakeInParam("@gold", SqlDbType.Int, 4, gold) };
        //    SqlHelper.ExecuteNonQuery("server=122.227.23.112,3433;User ID='tenroom';Password='tenroom';database=TenRoomTest;Connection Reset=FALSE", CommandType.StoredProcedure, "updatePoint", pars);
        //}

    }

    /// <summary>
    /// 判断该用户是否已近在游戏列表中存在
    /// </summary>
    /// <param name="idx">用户的idx</param>
    /// <returns></returns>
    public bool IsExist(int idx)
    {

        SqlParameter[] pars ={ SqlHelper.MakeInParam("@idx", SqlDbType.Int, 4, idx) };
        int len = (int)SqlHelper.ExecuteScalar(constr, CommandType.StoredProcedure, "IsExist", pars);
        if (len > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    /// <summary>
    /// 增加游戏列表信息
    /// </summary>
    /// <param name="idx">用户idx</param>
    public void Add(int idx)
    {
        SqlParameter[] pars ={ SqlHelper.MakeInParam("@idx", SqlDbType.Int, 4, idx) };
        SqlHelper.ExecuteNonQuery(constr, CommandType.StoredProcedure, "add_user", pars);
    }


    /// <summary>
    /// 修改游戏列表信息
    /// </summary>
    /// <param name="idx">用户idx</param>
    /// <param name="level">层数</param>
    public void updateLevel(int idx, int level)
    {

        SqlParameter[] pars ={ SqlHelper.MakeInParam("@idx", idx), SqlHelper.MakeInParam("@level", level) };
        SqlHelper.ExecuteNonQuery(constr, CommandType.StoredProcedure, "updateLevel", pars);

    }

    /// <summary>
    /// 判断用户是否已近通过相应的关数
    /// </summary>
    /// <param name="idx">用户idx</param>
    /// <param name="level">层数</param>
    /// <returns></returns>
    public bool IsPassed(int idx, int level)
    {

        int result = 0;
        SqlParameter[] pars ={ SqlHelper.MakeInParam("@idx", SqlDbType.Int, 4, idx), SqlHelper.MakeInParam("@level", SqlDbType.Int, 4, level), SqlHelper.MakeOutParam("@result", SqlDbType.Int, 4) };
        SqlHelper.ExecuteNonQuery(constr, CommandType.StoredProcedure, "IsPassed", pars);
        result = Convert.ToInt32(pars[2].Value);
        if (result == 1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }


    /// <summary>
    /// 得到用户金币数
    /// </summary>
    /// <param name="idx">用户id</param>
    /// <returns></returns>
    public int GetGold(int idx)
    {
        int gold = 0;
        SqlParameter[] pars ={ SqlHelper.MakeInParam("@idx", SqlDbType.Int, 4, idx), SqlHelper.MakeOutParam("@gold", SqlDbType.Int, 4) };
        SqlHelper.ExecuteNonQuery(constr, CommandType.StoredProcedure, "getgold", pars);
        gold = Convert.ToInt32(pars[1].Value);
        return gold;
    }


    /// <summary>
    /// 判断用户是否是VIP
    /// </summary>
    /// <param name="idx">用户id</param>
    /// <returns></returns>
    public bool IsVIP(int idx)
    {
        int result = 0;
        SqlParameter[] pars ={ SqlHelper.MakeInParam("@idx", SqlDbType.Int, 4, idx), SqlHelper.MakeOutParam("@result", SqlDbType.Int, 4) };
        SqlHelper.ExecuteNonQuery(constr, CommandType.StoredProcedure, "IsVIP", pars);
        result = Convert.ToInt32(pars[1].Value);
        if (result == 1)
        {
            return true;
        }
        else
        {
            return false;
        }

    }
}
